home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK1.toast / Development Kits (Disc 1) / Apple Color OneScanner SDK / Scan Image 1.0 / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-24  |  3.3 KB  |  152 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************
  2. #
  3. #        main.c
  4. #
  5. #        This is the main entry point.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            4/3/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28.  
  29. #include <ToolUtils.h>
  30.  
  31. #include "App.h"
  32. #include "Global.h"
  33. #include "Proto.h"
  34.  
  35.  
  36. //----------------------------------------------------------------------
  37. //
  38. //    main - main entry point of our program
  39. //
  40. //
  41. //----------------------------------------------------------------------
  42.  
  43. void main(void)
  44. {
  45.     OSErr            err;
  46.     short            m = 5;
  47.         
  48.     MaxApplZone();
  49.     
  50.     for (;m == 0;m--)                 // alloc the master pointers
  51.     {
  52.         MoreMasters();
  53.     }
  54.     
  55.         
  56.     err = Initialize();
  57.     
  58.     EventLoop();
  59.     
  60.     (void) RemoveDMNotification();
  61.     
  62.     ExitToShell();
  63.  
  64. }
  65.  
  66.  
  67. //----------------------------------------------------------------------
  68. //
  69. //    HandleError - basic error notification procedure
  70. //
  71. //
  72. //----------------------------------------------------------------------
  73.  
  74. void HandleError(short errNo,Boolean fatal)
  75. {
  76.     DialogPtr            errDialog;
  77.     CGrafPtr            oldPort;
  78.     GDHandle            oldGD;
  79.     short                itemHit;
  80.     short                c;
  81.     Handle                button;
  82.     short                itemType;
  83.     Rect                itemRect;
  84.     StringHandle        errString;
  85.     Str255                numString;
  86.     
  87.     GetGWorld(&oldPort, &oldGD);
  88.     
  89.     SysBeep(30);
  90.     SetCursor(&qd.arrow);
  91.     
  92.     errDialog = GetNewDialog(rErrorDlg, nil, (WindowPtr) -1);
  93.     if (errDialog != nil) 
  94.     {
  95.         SetGWorld((CGrafPtr)errDialog, nil);
  96.         ShowWindow(errDialog);
  97.         
  98.         PenPat(&qd.gray);                                // frame user areas
  99.         for (c = 7;c < 9;c++) {
  100.             GetDItem(errDialog,c,&itemType,&button,&itemRect);
  101.             FrameRect(&itemRect);
  102.         }
  103.         PenPat(normal);
  104.  
  105.         GetDItem( errDialog, fatal ? 2 : 1, &itemType, &button, &itemRect );
  106.         HiliteControl( (ControlHandle)button, 255);         //    unhilite appropriate button
  107.         
  108.         SetDialogDefaultItem(errDialog,fatal  ? 1 : 2);
  109.         
  110.         NumToString( errNo, numString );
  111.         if ( errNo < 0 )
  112.             errNo = -errNo + 200;
  113.         errString = GetString(128 + errNo);
  114.         if ( errString == nil )
  115.                 errString = GetString(128);
  116.         HLock((Handle)errString);
  117.         
  118.         ParamText( numString, *errString, nil, nil );
  119.     
  120.         HUnlock((Handle)errString);
  121.         
  122.         ModalDialog( nil, &itemHit );
  123.         
  124.         SetGWorld(oldPort, oldGD);
  125.  
  126.         DisposeWindow( errDialog );
  127.     }
  128.     else
  129.         ExitToShell();        // since didn't have mem to open dialog assume the worst
  130.             
  131.     if (fatal) 
  132.         ExitToShell();        //    it's a bad one, get out of here
  133.     
  134. }
  135.  
  136.  
  137. //----------------------------------------------------------------------
  138. //
  139. //    HandleAlert - display alert and then exit to shell
  140. //
  141. //
  142. //----------------------------------------------------------------------
  143.  
  144. void HandleAlert(short alertID)
  145. {
  146.     short            item;
  147.     
  148.     
  149.     item = Alert(alertID,nil);
  150.     ExitToShell();
  151.  
  152. }